package com.example.parkingproject.controller;

import com.example.parkingproject.jopo.dto.MouthUserAddDto;
import com.example.parkingproject.jopo.dto.MouthUserUpdateDto;
import com.example.parkingproject.jopo.vo.MouthUserVo;
import com.example.parkingproject.result.JsonResult;
import com.example.parkingproject.service.MouthUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mouthUser")
@Slf4j
public class MouthUserController {
    @Autowired
    MouthUserService mouthUserService;

    /*添加月租用户请求*/
    @PostMapping("/addMouthUser")
    public JsonResult addMouthUser(@RequestBody MouthUserAddDto mouthUserAddDto) {
        log.debug("开始处理{}", mouthUserAddDto);
        mouthUserService.addMouthUser(mouthUserAddDto);
        return JsonResult.ok();
    }

    /*查询月租用户列表请求*/
    @RequestMapping("/MouthUserList")
    public JsonResult<List<MouthUserVo>> addMouthUserList() {
        List<MouthUserVo> list = mouthUserService.MouthUserList();
        return JsonResult.ok(list);
    }

    /*删除月租用户*/
    @RequestMapping("/deleteMouthUser")
    public JsonResult deleteMouthUserByCardId(String cardId) {
        mouthUserService.deleteMouthUser(cardId);
        log.debug("传入参数{}", cardId);
        return JsonResult.ok();
    }

    /*拿到单个月租用户对象*/
    @RequestMapping("/getMouthUserByCard")
    public JsonResult<MouthUserVo> getMouthUser(String cardId) {
        MouthUserVo mouthUserVo = mouthUserService.getMouthUserByCard(cardId);
        log.debug("处理参数{}",mouthUserVo);
        return JsonResult.ok(mouthUserVo);
    }

    /*修改月租用户信息*/
    @RequestMapping("/updateMouthUserAll")
    public JsonResult updateMouthUserAll(@RequestBody MouthUserUpdateDto mouthUserUpdateDto){
        mouthUserService.updateMouthUserAll(mouthUserUpdateDto);
        return JsonResult.ok();
    }

    @RequestMapping("/search")
    public JsonResult<List<MouthUserVo>> search(@RequestBody MouthUserAddDto mouthUserAddDto){
        List<MouthUserVo> list = mouthUserService.search(mouthUserAddDto);
        return JsonResult.ok(list);
    }
}
